﻿using System;
using System.Collections.Generic;
using IQIGame.Onigao.GamePlay;
using LFloatMath.Math;

namespace IQIGame.Onigao.Logic
{
    public class FormulaFunction_Skill : FormulaFunction
    {
        public override EFormulaFunctionType funcType => EFormulaFunctionType.bSkill;

        public override void Calculate(Stack<IFormulaOperand> rCalopd, IFormulaObject rSelf, IFormulaObject rTarget, Formula rFromFormula)
        {
            IFormulaOperand opd1 = rCalopd.Pop();
            if (opd1.TryGet<LFloat>(out var op1, rSelf, rTarget, rFromFormula))
            {
                var nResult = 0;
                var nType = op1.ToInt();
                if (rFromFormula.bindingSkill != null)
                {
                    var rSkill = rFromFormula.bindingSkill;
                    switch (nType)
                    {
                        case 1:// 技能等级
                            nResult = rSkill.lv;
                            break;
                    }
                }
                
                IFormulaOperand result = FormulaHelper.FetchOperand(EFormulaOperandType.Num);
                result.Set(nResult.ToLFloat());
                rCalopd.Push(result);
            }
            else
            {
                throw new Exception($"{funcType} func need two number");
            }

            opd1.TryFree();
        }
    }
}